/**
 * nodeJs操作MongoDB
 */
//1、引入MongoDB下的mongoClient
const mongoClient = require("mongodb").MongoClient;

//2、定义数据库连接地址
const sql_url = "mongodb://localhost:27017/";
const db_name = "bidding-system";

//3、nodejs连接数据库
mongoClient.connect(sql_url + db_name, {useNewUrlParser: true}, function (err, client) {
  if (err) {
    console.log("mongodb数据库连接失败！" + err);
    return false;
  }
  console.log("mongodb数据库连接成功！");

  global.getDB = () => {
    return client.db(db_name)
  }
});

module.exports = mongoClient;
